package com.springbootbase.springbootproject.mapper;


import com.springbootbase.springbootproject.pojo.Teacher;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;

@Mapper
public interface TeacherMapper {


    @Select("select * from teacherinfo where id =#{id}")
        Teacher findById(Long id);

    @Update("UPDATE teacherinfo SET university = #{university}, department = #{department}, searchWay = #{searchWay}, title = #{title}, mainPage = #{mainPage}, introduce = #{introduce}, email = #{email}, phone = #{phone},hindex=#{hindex},hobby=#{hobby} WHERE id = #{id}")
    void updateTeacher(Teacher teacher);

    @Select("SELECT * FROM teacherinfo where exists(select 1 from user where user.id=#{id} and userType='admin') limit #{offset},#{pageSize}")
    ArrayList<Teacher> getList(Long id, int offset, int pageSize);

    @Select("select username from user where id=#{id}")
    String getNameById(Long id);

    @Select("SELECT COUNT(*) FROM teacherinfo where exists(select 1 from user where user.id=#{id} and userType='admin')")
    int countAllTeacherInfo(Long id);
}
